package com.solo.filterdemo01;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.io.PrintWriter;

// @WebFilter(filterName = "Filter2", urlPatterns = "/Servlet01")
public class Filter2 implements Filter {
    public void init(FilterConfig filterConfig) {}

    public void destroy() {}

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
            throws ServletException, IOException
    {
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();

        out.println("<b> Filter2过滤请求 : </b>");
        out.println("Hello " + request.getParameter("name") + "!");

        out.println("<br/>");

        chain.doFilter(request, response);

        out.println("<br/>");

        out.println("<b> Filter2 处理响应 : </b>");
        out.println("Bye " + request.getParameter("name") + "!");
    }
}
